package com.jiawei.栈;

import com.jiawei.链表.LinkedList;
import com.jiawei.链表.单链表.LinkedListSingle;

/**
 * @author : willian fu
 * @version : 1.0
 * 栈 链表实现
 */
public class LinkedListStack<E> implements Stack<E>{

    private LinkedList<E> stack;

    public LinkedListStack() {
        this.stack = new LinkedListSingle<>();
    }

    /**
     * 出栈
     *
     * @return
     */
    @Override
    public E pop() {
        if (this.stack.size() > 0){
            return this.stack.remove();
        }
        System.out.println("当前栈已空");
        return null;
    }

    /**
     * 入栈
     *
     * @param val
     * @return
     */
    @Override
    public void push(E val) {
        this.stack.add(val);
    }

    /**
     * 输出栈元素
     */
    @Override
    public void print() {
        this.stack.print();
    }
}
